+2007-01-07 Matthias Clasen <mclasen@redhat.com>
+
+ * xdgmimecache.c (_xdg_mime_cache_list_mime_parents): Fix
+ several problems with this function. (fd.o #9560, Yevgen Muntyan)
+
2006-08-17 Matthias Clasen <mclasen@redhat.com>
* === Released 2.10.2 ===
char **
_xdg_mime_cache_list_mime_parents (const char *mime)
{
- int i, j, p;
+ int i, j, k, p;
char *all_parents[128]; /* we'll stop at 128 */
char **result;
+ mime = xdg_mime_unalias_mime_type (mime);
+
p = 0;
for (i = 0; _caches[i]; i++)
{
for (j = 0; j < n_entries; j++)
{
- xdg_uint32_t mimetype_offset = GET_UINT32 (cache->buffer, list_offset + 4 + 8 * i);
- xdg_uint32_t parents_offset = GET_UINT32 (cache->buffer, list_offset + 4 + 8 * i + 4);
-
+ xdg_uint32_t mimetype_offset = GET_UINT32 (cache->buffer, list_offset + 4 + 8 * j);
+ xdg_uint32_t parents_offset = GET_UINT32 (cache->buffer, list_offset + 4 + 8 * j + 4);
+
if (strcmp (cache->buffer + mimetype_offset, mime) == 0)
{
+ xdg_uint32_t parent_mime_offset;
xdg_uint32_t n_parents = GET_UINT32 (cache->buffer, parents_offset);
-
- for (j = 0; j < n_parents; j++)
- all_parents[p++] = cache->buffer + parents_offset + 4 + 4 * j;
+
+ for (k = 0; k < n_parents && p < 127; k++)
+ {
+ parent_mime_offset = GET_UINT32 (cache->buffer, parents_offset + 4 + 4 * k);
+ all_parents[p++] = cache->buffer + parent_mime_offset;
+ }
break;
}